home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / compress / arj_992a.lzh / MODE_1-3.S < prev    next >
Text File  |  1994-08-07  |  15KB  |  588 lines

  1. ;
  2. ; ARJ Mode 1-3 decode functions
  3. ; Size optimized
  4. ; (c) 1993 Mr Ni! (the Great) of the TOS-crew
  5. ;
  6. ; This function uses a BIG amount of stack space!
  7. ; It uses about 16kB!
  8. ; You can reduce this amount with 13320 bytes
  9. ; by suppyling A3 with a pointer to a 13320 bytes big
  10. ; workspace and removing the stack allocation and
  11. ; deallocation code at the right places in the source
  12. ; text. (total is 3 lines, 2 at the start, 1 at main rts)
  13. ;
  14. ;void decode(ulong origsize, char* depack_space, char* packed_data)
  15. ;
  16. ; CALL:
  17. ; D0 = Origsize
  18. ; A0 = ptr to depack space
  19. ; A1 = ptr to packed data
  20. ;
  21. ; RETURN
  22. ; depacked data in depack space
  23. ;
  24.  
  25. workspacesize   EQU 13320
  26. pointer         EQU 0
  27. rbuf_current    EQU 4
  28. c_table         EQU 8
  29. c_len           EQU 8200
  30. avail           EQU 8710
  31. left            EQU 8712
  32. right           EQU 10750
  33. pt_len          EQU 12788
  34. pt_table        EQU 12808
  35.  
  36.  
  37. ; register usage:
  38. ; D0 =
  39. ; D1 =
  40. ; D2 = temporary usage
  41. ; D3 = byte count
  42. ; D4 = command tri-nibble
  43. ; D5 = const:  #$100
  44. ; D6 = bitbuf, subbitbuf
  45. ; D7 = .H: command count, .B: bits in subbitbuf
  46. ;
  47. ; A0 = klad
  48. ; A1 = rbuf_current
  49. ; A2 = c_table
  50. ; A3 = workspace_ptr
  51. ; A4 = text_pointer
  52. ; A5 = c_len
  53. ; A6 = copy_pointer
  54. ; A7 = Stack pointer
  55. decode:
  56.      movem.l D3-D7/A2-A6,-(SP) ;
  57.      lea     -workspacesize(SP),SP ; or supply your own workspace here
  58.      lea     (SP),A3         ; remove if alternative workspace supplied
  59.      movea.l A0,A4           ; depack space
  60.      move.l  D0,D3           ; origsize
  61.      moveq   #0,D7           ; bitcount = 0
  62.      move.w  A1,D0           ; for checking rbuf_current
  63.      btst    D7,D0           ; does readbuf_current point to an even address?
  64.      beq.s   .cont           ; yes
  65.      move.b  (A1)+,D6        ; pop eight  bits
  66.      moveq   #8,D7           ; 8 bits in subbitbuf
  67.      lsl.w   #8,D6
  68. .cont:
  69.      moveq   #$10,D4         ; push 16 (8) bits into bitbuf
  70.      sub.w   D7,D4           ; subtract still available bits from  d5
  71.      lsl.l   D7,D6
  72.      move.w  (A1)+,D6        ; word in subbitbuf
  73.      lsl.l   D4,D6           ; fill bitbuf
  74.      swap    D6
  75.      lea     c_len-pointer(A3),A5 ;
  76.      lea     c_table-c_len(A5),A2
  77.      lea     pt_table-c_len(A5),A0 ;
  78. .count_loop:
  79.      move.w  D6,D2           ; bitbuf in d2
  80.      swap    D7              ; size of Hufmann-block
  81.      dbra    D7,.bnz_cont    ; Hufmann block size > 0?
  82.  
  83. .blocksize_zero:             ; load a new Hufmann table
  84.      movem.l D3/A0/A2/A4,-(SP)
  85.      move.w  D2,D7           ; blocksize
  86.      subq.w  #1,D7           ; adapt blocksize for dbra
  87.      swap    D7              ; bitcount to LSW
  88.      moveq   #$10,D0         ; pop 16 bits
  89.      bsr     fillbits
  90.      moveq   #$03,D2         ; call-values for read_pt_len()
  91.      moveq   #$05,D1         ;
  92.      moveq   #$13,D0         ;
  93.      bsr     read_pt_len     ; call read_pt_len
  94.      movea.l rbuf_current-c_len(A5),A1
  95. ;void read_c_len(void)       ;
  96.      bsr.s   .get_them2
  97.      move.w  D2,D0
  98.      bne.s   .n_niet_nul     ;
  99.      bsr.s   .get_them2
  100.      lea     (A5),A0         ;
  101.      moveq   #$7F,D1         ;
  102. .loop_1:
  103.      clr.l   (A0)+           ; clear table
  104.      dbra    D1,.loop_1
  105.      lea     c_table-pointer(A3),A0
  106.      move.w  #$0FFF,D1
  107. .loop_2:
  108.      move.w  D2,(A0)+
  109.      dbra    D1,.loop_2
  110.      bra     .einde
  111.  
  112. .get_them2:
  113.      moveq   #9,D0           ;
  114.      move.w  D6,D2           ; bitbuf
  115.      lsr.w   #7,D2           ; shift 'old' bits
  116.      bra     fillbits
  117.  
  118. .n_niet_nul:                 ; *******************************
  119. ;
  120. ; Register usage:
  121. ;
  122. ; d0
  123. ; d1
  124. ; d2
  125. ; d3
  126. ; d4
  127. ; d5 = $13
  128. ; d6 = .l (sub) bitbuf
  129. ; d7 = .b bits in bitbuf
  130. ;
  131. ; a0 = temporary usage
  132. ; a1 = rbuf_current
  133. ; a2 = right
  134. ; a3 = rbuf_tail
  135. ; a4 = pt_table
  136. ; a5 = c_len
  137. ; a6 = left
  138. ; a7 = sp
  139. ;
  140.      lea     pt_table-c_len(A5),A4 ; pt_table
  141.      lea     right-c_len(A5),A2 ; right
  142.      lea     left-c_len(A5),A6 ; left
  143.      move.w  D0,D3           ; count
  144.      moveq   #0,D4           ;
  145.      moveq   #$13,D5         ;
  146.      moveq   #0,D0           ;
  147. .loop_3:
  148.      move.w  D6,D0           ; sub bitbuf
  149.      lsr.w   #8,D0           ; upper 8 bits
  150.      add.w   D0,D0           ;
  151.      move.w  0(A4,D0.w),D2   ; check pt_table
  152.      bge.s   .c_kleiner_NT   ;
  153.      neg.w   D2
  154.      moveq   #7,D0           ;
  155.      move.w  D6,D1           ; bitbuf
  156. .loop_4:                     ;
  157.      add.w   D2,D2           ;
  158.      btst    D0,D1           ;
  159.      beq.s   .links          ;
  160.      move.w  0(A2,D2.w),D2   ;
  161.      cmp.w   D5,D2           ;
  162.      dbcs    D0,.loop_4      ;
  163.      bra.s   .c_kleiner_NT   ;
  164. .links:                      ;
  165.      move.w  0(A6,D2.w),D2   ;
  166.      cmp.w   D5,D2           ;
  167.      dbcs    D0,.loop_4      ;
  168.  
  169. .c_kleiner_NT:               ;
  170.      move.b  pt_len-pt_table(A4,D2.w),D0 ;
  171.      bsr     fillbits
  172.      cmp.w   #2,D2           ;
  173.      bgt.s   .c_groter_2     ;
  174.      beq.s   .c_niet_1       ;
  175.      tst.w   D2              ;
  176.      beq.s   .loop_5_init    ;
  177.      moveq   #4,D0
  178.      bsr     getbits
  179.      addq.w  #2,D2           ;
  180.      bra.s   .loop_5_init    ;
  181. .c_niet_1:
  182.      bsr.s   .get_them2
  183.      add.w   D5,D2           ;
  184. .loop_5_init:
  185.      moveq   #0,D0           ;
  186.      lea     0(A5,D4.w),A0   ;
  187.      add.w   D2,D4           ;
  188. .loop_5:
  189.      move.b  D0,(A0)+        ;
  190.      dbra    D2,.loop_5      ;
  191.      bra.s   .loop_3_test    ;
  192. .c_groter_2:
  193.      moveq   #0,D0           ;
  194.      subq.w  #2,D2           ;
  195.      move.b  D2,0(A5,D4.w)   ;
  196. .loop_3_test:
  197.      addq.w  #1,D4           ;
  198.      cmp.w   D4,D3           ;
  199.      bgt.s   .loop_3         ;
  200.      move.w  #$01FE,D1       ;
  201.      sub.w   D4,D1           ;
  202.      lea     0(A5,D4.w),A0   ;
  203.      bra.s   .loop_6_test    ;
  204. .loop_6:
  205.      move.b  D0,(A0)+        ;
  206. .loop_6_test:
  207.      dbra    D1,.loop_6      ;
  208.      move.l  A1,rbuf_current-c_len(A5)
  209.      lea     c_table-c_len(A5),A1 ;
  210.      moveq   #$0C,D1         ;
  211.      movea.l A5,A0           ;
  212.      move.w  #$01FE,D0       ;
  213.      bsr     make_table      ;
  214.      movea.l rbuf_current-c_len(A5),A1
  215. .einde:
  216.      moveq   #-1,D2          ;
  217.      moveq   #$05,D1         ;
  218.      moveq   #$11,D0         ;
  219.      bsr     read_pt_len     ;
  220.      movea.l rbuf_current-c_len(A5),A1
  221.      movem.l (SP)+,D3/A0/A2/A4
  222.      move.w  #$0100,D5       ; constant
  223.      swap    D7              ; blocksize to LSW
  224.      move.w  D6,D2
  225.  
  226. ;***********************
  227. ;
  228. ; Register usage:
  229. ;
  230. ; d0 = temporary usage
  231. ; d1 = temporary usage
  232. ; d2 = temporary usage
  233. ; d3 = loopcount
  234. ; d4 = command byte
  235. ; d5 = const: $100
  236. ; d6 = (sub)bitbuf
  237. ; d7 = .h: command count, .b byte count
  238. ;
  239. ; a0 = pt_table
  240. ; a1 = rbuf_current
  241. ; a2 = c_table
  242. ; a3 = rbuf_tail
  243. ; a4 = text
  244. ; a5 = c_len
  245. ; a6 = source pointer
  246. ; a7 = (sp)
  247.  
  248. .bnz_cont:
  249.      swap    D7              ; bitcount in LSW d7
  250.      lsr.w   #4,D2           ; charactertable is 4096 bytes (=12 bits)
  251.      add.w   D2,D2
  252.      move.w  0(A2,D2.w),D2   ; pop character
  253.      bmi.s   .j_grotergelijk_nc
  254. .decode_c_cont:              ;
  255.      move.b  0(A5,D2.w),D0   ; pop 'charactersize' bits from buffer
  256.      bsr     fillbits
  257.      sub.w   D5,D2           ;
  258.      bcc.s   .sliding_dic    ;
  259.      move.b  D2,(A4)+        ; push character into buffer
  260.      subq.l  #1,D3
  261.      bne     .count_loop
  262. .decode_einde:
  263.      lea     workspacesize(SP),SP; remove if alternative workspace supplied
  264.      movem.l (SP)+,D3-D7/A2-A6 ;
  265.      rts                     ;
  266.  
  267. .j_grotergelijk_nc:
  268.      moveq   #$03,D1         ;
  269.      move.w  #$01FE,D0
  270.      bsr.s   .fidel_no
  271.      bra.s   .decode_c_cont  ;
  272.  
  273. .p_j_grotergelijk_np:
  274.      moveq   #$07,D1         ;
  275.      moveq   #$11,D0
  276.      bsr.s   .fidel_no
  277.      bra.s   .p_cont         ;
  278.  
  279. .fidel_no:
  280.      neg.w   D2
  281.      lea     left-c_len(A5),A0 ;
  282.      lea     right-left(A0),A6 ;
  283. .mask_loop:
  284.      add.w   D2,D2           ;
  285.      btst    D1,D6           ;
  286.      bne.s   .bitbuf_en_mask ;
  287.      move.w  0(A0,D2.w),D2   ;
  288.      cmp.w   D0,D2           ;
  289.      dbcs    D1,.mask_loop   ;
  290.      lea     pt_table-c_len(A5),A0 ;
  291.      rts
  292. .bitbuf_en_mask:
  293.      move.w  0(A6,D2.w),D2   ;
  294.      cmp